#ifndef __GAMELAYER_H__
#define __GAMELAYER_H__

#include "cocos2d.h"
#include "DataStructure/DataStruct.h"
#include "GameLayerConfig.h"

USING_NS_CC;


/*
class GameLayer;
class GameLayerMenu : public CCMenu
{
public:
	GameLayerMenu(GameLayer* parent):mParent(parent) {}
	virtual void ccTouchEnded(CCTouch* touch, CCEvent* event);
private:
	GameLayer* mParent;
};
*/

#define REGIST_LAYER_CREATE(class) \
	static class* Create() \
	{\
		class *pRet = new class();\
		if (pRet && pRet->init())\
		{\
			pRet->autorelease();\
			return pRet;\
		}\
		else\
		{\
			delete pRet;\
			pRet = 0;\
			return 0;\
		}\
	}

class GameLayer : public CCLayer
{
public:
	GameLayer()
	{
		mZOrder=0;
		mMenu=0;
		setAnchorPoint(ccp(0,0));
		setPosition(ccp(0,0));
		setTouchEnabled(false);
	}
	~GameLayer(void)
	{

	}
public:
	REGIST_LAYER_CREATE(GameLayer);
	virtual bool OnInit() {return true;}
public:
	bool init();
	void AddChild(CSString name,CCNode* child,int z);
	void AddChild(GameLayerConfigElem* elem,CCNode* child);
	int GetZOrder(){return mZOrder;}
	void SetZOrder(int z) {mZOrder=z;}
	virtual bool Commond(CCNode* sender,CSString event);
	bool IsMatch(CSString name,CCNode* node);
private:
	int mZOrder;
	CCMenu* mMenu;
	CSHashMap<CSString,CCNode*> mUIItems;
};

class CCMenuButton : public CCMenuItemSprite
{
public:
	CCMenuButton():mTxtLabel(0) {}
	~CCMenuButton() {}
public:
	static CCMenuButton* Create()
	{
		CCMenuButton* ret = new CCMenuButton();
		if(!ret)
			return 0;
		ret->autorelease();
		return ret;
	}
	void init(GameLayerConfigButton* elem);
	void SetCaption(CSString str);
	void activate();
private:
	CCLabelTTF* mTxtLabel;
};

#endif
